package com.frame.work.frame.deal.device0faa;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.config.SpringUtil;
import com.frame.work.entity.TblDeviceActions;
import com.frame.work.frame.deal.base.BaseFrame;
import com.frame.work.mapper.SelectDeviceMapper;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.frame.work.common.constant.CallType.TYPE_GET;
import static com.frame.work.common.constant.CallType.TYPE_SET;

/**
 * 六路场景面板0DAA8A05
 */
@Data
public class LiuLuChangJingMianBan_0FAA8A05 extends BaseFrame {

    private Integer switchState;

    public LiuLuChangJingMianBan_0FAA8A05(String gatewayMac, String data, String type) {
        //将基础数据进行处理
        super(gatewayMac, data);
        //根据不同类型进行判断
        if (TYPE_GET.equals(type)) {
            LiuLuChangJingMianBan_0FAA8A05Get(gatewayMac, data);
        } else if (TYPE_SET.equals(type)) {
            LiuLuChangJingMianBan_0FAA8A05Set(gatewayMac, data);
        }
    }


    public void LiuLuChangJingMianBan_0FAA8A05Get(String gatewayMac, String data) {


        //处理此设备特有的数据
        String after0FAA = StringUtils.substring(data, 22, 24);
        this.setSwitchState(-100);
        String nightLightTime = "";
        //先查询数据库
        SelectDeviceMapper testMapper = (SelectDeviceMapper) SpringUtil.getBean(SelectDeviceMapper.class);
        List<TblDeviceActions> list = testMapper.getDevice2(this.getDeviceMac(), this.getOdIndex(), this.getDeviceType(), this.getProductType());
        if (list.size() == 0) {
            nightLightTime = "02";
        }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getActionsKey() == "nightLightTime") {
                nightLightTime = (String) list.get(i).getActionsValue();
            }
        }


        //如果nightLightTime不为null则运行以下代码
        //暂设空值

        if (nightLightTime != null) {


            if ("FF".equals(after0FAA)) {

                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_TRIGGER");
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);

            } else if ("01".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 1);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("02".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 2);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("03".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 3);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("04".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 4);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("05".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 5);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("06".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 6);
                actions.put("sceneNumber", sceneNumber);
                actions.put("nightLightTime", nightLightTime);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            }
        } else {

            if ("FF".equals(after0FAA)) {

                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_TRIGGER");
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);

            } else if ("01".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 1);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("02".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 2);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("03".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 3);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("04".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 4);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("05".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 5);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            } else if ("06".equals(after0FAA)) {
                String sceneNumber = StringUtils.substring(data, data.length() - 2, data.length());

                //将actions信息放入json对象中
                Map<String, Object> actions = new HashMap();
                actions.put("controlType", "SCENE_NUMBER_GET");
                actions.put("wayNumber", 6);
                actions.put("sceneNumber", sceneNumber);
                this.setActions(actions);

                //处理好的json对象
                String json = JSONObject.toJSONString(this);
                //将数据发送到mqtt队列中
                JsonToMqtt.sendMQTT(gatewayMac, json);


            }

        }


    }


    public void LiuLuChangJingMianBan_0FAA8A05Set(String gatewayMac, String data) {

        this.setOdIndex("0FAA");
        this.setDeviceType("8A");
        this.setProductType("05");
        this.setSwitchState(-100);

        //处理此设备特有的数据
        String afterOdIndex = StringUtils.substring(data, 22, 24);
        String state = StringUtils.substring(data, 24, 26);

        if ("01".equals(afterOdIndex)) {


            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 1);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        } else if ("02".equals(afterOdIndex)) {

            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 2);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        } else if ("03".equals(afterOdIndex)) {

            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 3);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);


        } else if ("04".equals(afterOdIndex)) {

            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 4);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        } else if ("05".equals(afterOdIndex)) {

            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 5);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        } else if ("06".equals(afterOdIndex)) {

            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("controlType", "SCENE_NUMBER_SET");
            actions.put("wayNumber", 6);
            actions.put("state", state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        }


    }

}
